#encoding: utf-8
class ApplicationController < ActionController::Base
  protect_from_forgery
  helper :all
  helper_method :authenticate, :current_user, :current_user_session, :current_customer_session, :current_customer
  
  protected
  
  def current_customer_session
    @current_customer_session ||= CustomerSession.find
  end
  
  def current_customer
    @current_customer ||= current_customer_session && current_customer_session.customer
  end
  
=begin
 返回当前user_session
=end
  def current_user_session
    @current_user_session ||= UserSession.find
  end
  
=begin
 返回当前user
=end
  def current_user
    @current_user ||= current_user_session &&  current_user_session.user
  end

=begin
 判断用户是否登录
=end
  def authenticate
    unless current_user
      flash[:notice] = "对不起，您还没有登录!"
      redirect_to new_user_session_path
      return false
    end
  end
  
=begin
	判断商户是否登录	
=end
	def authenticate_customer
		unless current_customer
			flash[:notice] = "对不起，您还没有登录!"
			redirect_to new_customer_session_path
			return false
		end
	end
end
